home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / konq_dirpart.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.0 KB  |  352 lines

  1. /* This file is part of the KDE projects
  2.    Copyright (C) 2000 David Faure <faure@kde.org>
  3.  
  4.    This program is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  12.     General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; see the file COPYING.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __konqdirpart_h
  21. #define __konqdirpart_h
  22.  
  23. #include <qstring.h>
  24. #include <kparts/part.h>
  25. #include <kparts/browserextension.h>
  26. #include <kfileitem.h>
  27. #include <kdatastream.h>
  28. #include <kio/global.h>
  29. #include <libkonq_export.h>
  30.  
  31. class KDirLister;
  32. namespace KParts { class BrowserExtension; }
  33. class KonqPropsView;
  34. class QScrollView;
  35. class KAction;
  36. class KToggleAction;
  37. class KonqDirPartBrowserExtension;
  38.  
  39. class LIBKONQ_EXPORT KonqDirPart: public KParts::ReadOnlyPart
  40. {
  41.     Q_OBJECT
  42.  
  43.     friend class KonqDirPartBrowserExtension;
  44.  
  45. public:
  46.     KonqDirPart( QObject *parent, const char *name );
  47.  
  48.     virtual ~KonqDirPart();
  49.  
  50.     /**
  51.      * The derived part should call this in its constructor
  52.      */
  53.     void setBrowserExtension( KonqDirPartBrowserExtension * extension )
  54.       { m_extension = extension; }
  55.  
  56.     KonqDirPartBrowserExtension * extension()
  57.       { return m_extension; }
  58.  
  59.     /**
  60.      * The derived part should call this in its constructor
  61.      */
  62.     void setDirLister( KDirLister* lister );
  63.     // TODO KDE4 create the KDirLister here and simplify the parts?
  64.  
  65.     QScrollView * scrollWidget();
  66.  
  67.     virtual void saveState( QDataStream &stream );
  68.     virtual void restoreState( QDataStream &stream );
  69.  
  70.     /** Called when LMB'ing an item in a directory view.
  71.      * @param fileItem must be set
  72.      * @param widget is only set as parent pointer for dialog boxes */
  73.     void lmbClicked( KFileItem * fileItem );
  74.  
  75.     /** Called when MMB'ing an item in a directory view.
  76.      * @param fileItem if 0 it means we MMB'ed the background. */
  77.     void mmbClicked( KFileItem * fileItem );
  78.  
  79.     void setNameFilter( const QString & nameFilter ) { m_nameFilter = nameFilter; }
  80.  
  81.     QString nameFilter() const { return m_nameFilter; }
  82.  
  83.     void setFilesToSelect( const QStringList & filesToSelect ) { m_filesToSelect = filesToSelect; }
  84.  
  85.     /**
  86.      * Sets per directory mime-type based filtering.
  87.      *
  88.      * This method causes only the items matching the mime-type given
  89.      * by @p filters to be displayed. You can supply multiple mime-types
  90.      * by separating them with a space, eg. "text/plain image/x-png".
  91.      * To clear all the filters set for the current url simply call this
  92.      * function with a null or empty argument.
  93.      *
  94.      * NOTE: the filter(s) specified here only apply to the current
  95.      * directory as returned by @ref #url().
  96.      *
  97.      * @param filter mime-type(s) to filter directory by.
  98.      */
  99.     void setMimeFilter (const QStringList& filters);
  100.  
  101.     /**
  102.      * Completely clears the internally stored list of mime filters
  103.      * set by call to @ref #setMimeFilter.
  104.      */
  105.     QStringList mimeFilter() const;
  106.  
  107.  
  108.     KonqPropsView * props() const { return m_pProps; }
  109.  
  110.     /**
  111.      * "Cut" icons : disable those whose URL is in lst, enable the others
  112.      */
  113.     virtual void disableIcons( const KURL::List & lst ) = 0;
  114.  
  115.     /**
  116.      * This class takes care of the counting of items, size etc. in the
  117.      * current directory. Call this in slotClear.
  118.      */
  119.     void resetCount();
  120.  
  121.     /**
  122.      * Update the counts for those new items
  123.      */
  124.     void newItems( const KFileItemList & entries );
  125.  
  126.     /**
  127.      * Update the counts with this item being deleted
  128.      */
  129.     void deleteItem( KFileItem * fileItem );
  130.  
  131.     /**
  132.      * Show the counts for the directory in the status bar
  133.      */
  134.     void emitTotalCount();
  135.  
  136.     // ##### TODO KDE 4: remove!
  137.     /**
  138.      * Show the counts for the list of items in the status bar.
  139.      * If none are provided emitTotalCount() is called to display
  140.      * the counts for the whole directory. However, that does not work
  141.      * for a treeview.
  142.      * 
  143.      * @deprecated
  144.      */
  145.     void emitCounts( const KFileItemList & lst, bool selectionChanged );
  146.     
  147.     /**
  148.      * Show the counts for the list of items in the status bar. The list
  149.      * can be empty.
  150.      * 
  151.      * @param lst the list of fileitems for which to display the counts
  152.      * @since 3.4
  153.      */
  154.     void emitCounts( const KFileItemList & lst );
  155.  
  156.     void emitMouseOver( const KFileItem * item );
  157.  
  158.     /**
  159.      * Enables or disables the paste action. This depends both on
  160.      * the data in the clipboard and the number of files selected
  161.      * (pasting is only possible if not more than one file is selected).
  162.      */
  163.     void updatePasteAction();
  164.  
  165.     /**
  166.      * Change the icon size of the view.
  167.      * The view should call it initially.
  168.      * The view should also reimplement it, to update the icons.
  169.      */
  170.     virtual void newIconSize( int size );
  171.  
  172.     /**
  173.      * This is called by the actions that change the icon size.
  174.      * It stores the new size and calls newIconSize.
  175.      */
  176.     void setIconSize( int size );
  177.  
  178.     /**
  179.      * This is called by konqueror itself, when the "find" functionality is activated
  180.      */
  181.     void setFindPart( KParts::ReadOnlyPart * part );
  182.  
  183.     KParts::ReadOnlyPart * findPart() const { return m_findPart; }
  184.  
  185.     virtual const KFileItem * currentItem() = 0; // { return 0L; }
  186.  
  187.     virtual KFileItemList selectedFileItems() { return KFileItemList(); }
  188.  
  189.     /**
  190.      * Re-implemented for internal reasons.  API is unaffected.  All inheriting
  191.      * classes should re-implement @ref doCloseURL() instead instead of this one.
  192.      */
  193.     bool closeURL ();
  194.  
  195. signals:
  196.  
  197.     /**
  198.      * Emitted whenever the current URL is about to be changed.
  199.      */
  200.     void aboutToOpenURL();
  201.  
  202.     /**
  203.      * We emit this if we want a find part to be created for us.
  204.      * This happens when restoring from history
  205.      */
  206.     void findOpen( KonqDirPart * );
  207.  
  208.     /**
  209.      * We emit this _after_ a find part has been created for us.
  210.      * This also happens initially.
  211.      */
  212.     void findOpened( KonqDirPart * );
  213.  
  214.     /**
  215.      * We emit this to ask konq to close the find part
  216.      */
  217.     void findClosed( KonqDirPart * );
  218.  
  219.     /**
  220.      * Emitted as the part is updated with new items.
  221.      * Useful for informing plugins of changes in view.
  222.      */
  223.     void itemsAdded( const KFileItemList& );
  224.  
  225.     /**
  226.      * Emitted as the part is updated with these items.
  227.      * Useful for informing plugins of changes in view.
  228.      */
  229.     void itemRemoved( const KFileItem* );
  230.  
  231.     /**
  232.      * Emitted with the list of filtered-out items whenever
  233.      * a mime-based filter(s) is set.
  234.      */
  235.     void itemsFilteredByMime( const KFileItemList& );
  236.  
  237. public slots:
  238.  
  239.     /**
  240.      * Re-implemented for internal reasons.  API is unaffected.  All inheriting
  241.      * classes should re-implement @ref doOpenURL() instead instead of this one.
  242.      */
  243.      bool openURL (const KURL&);
  244.  
  245.     /**
  246.      * This is called either by the part's close button, or by the
  247.      * dir part itself, if entering a directory. It deletes the find
  248.      * part.
  249.      */
  250.     void slotFindClosed();
  251.  
  252.     /**
  253.      * Start the animated "K" during kfindpart's file search
  254.      */
  255.     void slotStartAnimationSearching();
  256.  
  257.     /**
  258.      * Start the animated "K" during kfindpart's file search
  259.      */
  260.     void slotStopAnimationSearching();
  261.  
  262.     void slotBackgroundSettings();
  263.  
  264.     /**
  265.      * Called when the clipboard's data changes, to update the 'cut' icons
  266.      * Call this when the directory's listing is finished, to draw icons as cut.
  267.      */
  268.     void slotClipboardDataChanged();
  269.  
  270.     void slotIncIconSize();
  271.     void slotDecIconSize();
  272.  
  273.     void slotIconSizeToggled( bool );
  274.  
  275.     // slots connected to the directory lister - or to the kfind interface
  276.     virtual void slotStarted() = 0;
  277.     virtual void slotCanceled() = 0;
  278.     virtual void slotCompleted() = 0;
  279.     virtual void slotNewItems( const KFileItemList& ) = 0;
  280.     virtual void slotDeleteItem( KFileItem * ) = 0;
  281.     virtual void slotRefreshItems( const KFileItemList& ) = 0;
  282.     virtual void slotClear() = 0;
  283.     virtual void slotRedirection( const KURL & ) = 0;
  284.  
  285. private slots:
  286.     void slotIconChanged(int group);
  287. protected:
  288.     /**
  289.      * Invoked from openURL to enable childern classes to
  290.      * handle open URL requests.
  291.      */
  292.     virtual bool doOpenURL( const KURL& ) = 0;
  293.     virtual bool doCloseURL () = 0;
  294.  
  295. protected:
  296.  
  297.     QString m_nameFilter;
  298.     QStringList m_filesToSelect;
  299.  
  300.     KonqPropsView * m_pProps;
  301.  
  302.     KAction *m_paIncIconSize;
  303.     KAction *m_paDecIconSize;
  304.     KToggleAction *m_paDefaultIcons;
  305.     KToggleAction *m_paHugeIcons;
  306.     KToggleAction *m_paLargeIcons;
  307.     KToggleAction *m_paMediumIcons;
  308.     KToggleAction *m_paSmallIcons;
  309.  
  310.     KParts::ReadOnlyPart * m_findPart;
  311.     KonqDirPartBrowserExtension * m_extension;
  312.  
  313.     // Remove all those in KDE4
  314.     int m_iIconSize[5];
  315.     KIO::filesize_t m_lDirSize;
  316.     uint m_lFileCount;
  317.     uint m_lDirCount;
  318.  
  319. private:
  320.     void saveFindState( QDataStream& );
  321.     void restoreFindState( QDataStream& );
  322.  
  323.     void adjustIconSizes();
  324.  
  325.     class KonqDirPartPrivate;
  326.     KonqDirPartPrivate* d;
  327. };
  328.  
  329. class LIBKONQ_EXPORT KonqDirPartBrowserExtension : public KParts::BrowserExtension
  330. {
  331. public:
  332.     KonqDirPartBrowserExtension( KonqDirPart* dirPart )
  333.         : KParts::BrowserExtension( dirPart )
  334.         , m_dirPart( dirPart )
  335.     {}
  336.  
  337.     /**
  338.      * This calls saveState in KonqDirPart, and also takes care of the "find part".
  339.      *
  340.      * If your KonqDirPart-derived class needs to save and restore state,
  341.      * you should probably override KonqDirPart::saveState
  342.      * and KonqDirPart::restoreState, not the following methods.
  343.      */
  344.     virtual void saveState( QDataStream &stream );
  345.     virtual void restoreState( QDataStream &stream );
  346.  
  347. private:
  348.     KonqDirPart* m_dirPart;
  349. };
  350.  
  351. #endif
  352.